# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=floskell
pkgname=haskell-floskell
pkgver=0.10.7
pkgrel=68
pkgdesc="A flexible Haskell source code pretty printer"
url="https://github.com/ennocramer/floskell"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-aeson-pretty' 'haskell-attoparsec'
         'haskell-data-default' 'haskell-src-exts' 'haskell-monad-dijkstra'
         'haskell-optparse-applicative' 'haskell-unordered-containers' 'haskell-utf8-string')
makedepends=('ghc' 'haskell-hspec')
source=("https://github.com/ennocramer/floskell/archive/floskell-$pkgver.tar.gz")
sha256sums=('b46c2bd16aaaf5d118793e622b69bf116aa3dea0d353bc2a573b7b52b7f1ff9b')

build() {
  cd $_hkgname-floskell-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $_hkgname-floskell-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $_hkgname-floskell-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE.md -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.md
}
